<?php
/**
 * Created by PhpStorm.
 * User: Thans
 * Date: 2018/6/26
 * Time: 下午12:11
 */

namespace app\common\service;

use think\facade\Config;

class TemplateService
{
    public function scanTemp()
    {
        $files = [];
        $module = request()->module();
        $theme = Config::get($module . '.' . 'theme') ? $module . '_' . Config::get($module . '.' . 'theme') : $module . '_default';
        $dir = 'theme/' . $theme . '/page';
        foreach (cmf_scan_dir($dir . '/*.html') as $val) {
            $val = str_replace('.html', '', $val);
            $files[] = $val;
        }
        $dirs = cmf_sub_dirs('theme/' . $theme . '/page');
        foreach ($dirs as $val) {
            cmf_scan_dir($val . '/*.html');
            $dir_name = str_replace($dir . '/', '', $val) . '/';
            foreach (cmf_scan_dir($dir . '/*.html') as $val) {
                $val = str_replace('.html', '', $dir_name . $val);
                $files[] = $val;
            }
        }
        return $files;
    }
}